@extends('backstage.layout.master')
@section('title', '人群列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="backstage/crowd/crowd-list">人群</a>
            </li>
            <li>
                人群列表
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
            <form class="form-search">
								<span class="input-icon">
									<input type="text" placeholder="搜索..." name="search" value="{{$crowds->search}}" class="nav-search-input"
                                           id="nav-search-input" autocomplete="off"/>
									<i class="icon-search nav-search-icon"></i>
								</span>
            </form>
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                人群
                <small>
                    <i class="icon-double-angle-right"></i>
                    人群列表
                </small>
                <span class="pull-right">
                    <button class="btn btn-primary" onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/add-crowd';">添加人群</button>
                </span>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>编号</th>
                            <th>人群名称</th>
                            <th class="hidden-480">人群描述</th>
                            <th></th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($crowds as $crowd)
                        <tr class="" data-tr-id="{{$crowd->id}}">
                            <td class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </td>
                            <td>{{isset($crowd->id)?$crowd->id:''}}</td>
                            <td>
                                {{isset($crowd->crowd_name)?$crowd->crowd_name:''}}
                            </td>

                            <td class="hidden-480">
                                {{str_limit($crowd->description, $limit = 15, $end = '...')}}
                            </td>

                            <td>
                                <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">

                                    <button onclick="javascript:window.location.href='{{asset('')}}backstage/product-temp/update-crowd?crowd_id={{$crowd->id}}';" class="btn btn-xs btn-info" data-rel="tooltip" title="修改">
                                        <i class="icon-edit bigger-120"></i>
                                    </button>

                                    <button class="btn btn-xs btn-danger" data-delete="{{$crowd->id}}" data-rel="tooltip" title="删除">
                                        <i class="icon-trash bigger-120"></i>
                                    </button>
                                </div>
                                <div class="visible-xs visible-sm hidden-md hidden-lg">
                                    <div class="inline position-relative">
                                        <button class="btn btn-minier btn-primary dropdown-toggle"
                                                data-toggle="dropdown">
                                            <i class="icon-cog icon-only bigger-110"></i>
                                        </button>

                                        <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">

                                            <li>
                                                <a target="_blank" href="backstage/product-temp/update-crowd?crowd_id={{$crowd->id}}" class="tooltip-success" data-rel="tooltip" title=""
                                                   data-original-title="修改">
													<span class="green">
														<i class="icon-edit bigger-120"></i>
													</span>
                                                </a>
                                            </li>
                                            <li>
                                                <a target="_blank" href="javascript:"  class="tooltip-error" data-delete="{{$crowd->id}}" data-rel="tooltip" title=""
                                                   data-original-title="删除">
													<span class="red">
													<i class="icon-trash bigger-120"></i>
													</span>
                                                </a>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </td>
                        </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $crowds->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function () {
                var crowd_id=$(this).attr("data-delete");
                swal({
                    title: "确定删除？",
                    text: "",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    closeOnConfirm: true,
                    closeOnCancel: true
                },function (){
                    $.ajax({
                        type: "post",
                        url: "/backstage/product-temp/delete-crowd",
                        data:{
                            crowd_id:crowd_id,
                            _token:"{{csrf_token()}}"
                        },
                        dataType: 'json',
                        success: function(res){
                            if(res.state==1){
                                swal({
                                    title:'删除成功！',
                                    text: "",
                                    type: "success",
                                    timer:2000
                                });
                                $('[data-tr-id='+crowd_id+']').remove();
                            }else{
                                swal({
                                    title: res.message,
                                    text: "",
                                    type: "error",
                                    timer:3000
                                });
                            }
                        },
                        error:function(){
                            swal({
                                title: "系统繁忙！",
                                text: "",
                                type: "error",
                                timer:8000
                            });
                        }
                    });//ajax
                });
            });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });

        });
    </script>
@stop